unit ufrmMain;
{
Criar opcao de backup de arquivo em txt quando acesso for exclusivo
Gerar os arquivo com nome backup-fisiofib-yyyymmddhhmm.bkp e
se houve 10 arquivos ou mais com este nome no diretorio o
programa nao pode funcionar para obrigar o usuario a fazer copia
destes arquivos

Criar o programa sendmailfile EnviaArquivoCorreio para enviar arquivos
anexados em e-mail. Para salvar, por exemplo, backup no e-mail (gmail)

// criar help explicando a estrutura do arquivo
// gerar exportacao de dados a partir do arquivo de backup
// gerar arquivo xls

// criar opcao de configuracao de acesso ao banco de dados atraves
da configuracao do arquivo .INI
}

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, XPMan, ImgList, ToolWin, ComCtrls, Menus, ExtCtrls, StrUtils;

type
  TfrmMain = class(TForm)
    XPManifest1: TXPManifest;
    MainMenu1: TMainMenu;
    StatusBar1: TStatusBar;
    mnuCadastro: TMenuItem;
    mnuPaciente: TMenuItem;
    mnuSair: TMenuItem;
    mnuMedico: TMenuItem;
    mnuEstagiario: TMenuItem;
    mnuSupervisor: TMenuItem;
    mnuEtapa: TMenuItem;
    mnuAjuda: TMenuItem;
    mnuAjuda2: TMenuItem;
    mnuSobre: TMenuItem;
    mnuUsuario: TMenuItem;
    mnuRelatorio: TMenuItem;
    mnuUtilitario: TMenuItem;
    mnuSeguranca: TMenuItem;
    EncerrarSesso1: TMenuItem;
    Permisso1: TMenuItem;
    Paciente1: TMenuItem;
    Mdico1: TMenuItem;
    Estagirio1: TMenuItem;
    Supervisor1: TMenuItem;
    Estatistica1: TMenuItem;
    mnuBackup: TMenuItem;
    mnuFazerBackup: TMenuItem;
    mnuRestaurarBackup: TMenuItem;
    mnuCalculadora: TMenuItem;
    Timer1: TTimer;
    ImgLstAtivo: TImageList;
    TBarReg: TToolBar;
    tbtPrimeiro: TToolButton;
    tbtAnterior: TToolButton;
    tbtProximo: TToolButton;
    tbtUltimo: TToolButton;
    ToolButton5: TToolButton;
    tbtNovo: TToolButton;
    tbtSalvar: TToolButton;
    tbtExcluir: TToolButton;
    tbtCancelar: TToolButton;
    procedure mnuSairClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure mnuPacienteClick(Sender: TObject);
    procedure mnuMedicoClick(Sender: TObject);
    procedure tbtPrimeiroClick(Sender: TObject);
    procedure tbtAnteriorClick(Sender: TObject);
    procedure tbtProximoClick(Sender: TObject);
    procedure tbtUltimoClick(Sender: TObject);
    procedure tbtNovoClick(Sender: TObject);
    procedure tbtSalvarClick(Sender: TObject);
    procedure tbtExcluirClick(Sender: TObject);
    procedure tbtCancelarClick(Sender: TObject);
    procedure SetaTBarReg(PStatus: string);
  private
    { Private declarations }
    procedure AtualizaBarraStatus;
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

uses ufrmMedico, ufrmPaciente;

{$R *.dfm}

procedure TfrmMain.mnuSairClick(Sender: TObject);
begin
  close;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  Top := Screen.WorkAreaTop;
  Left := Screen.WorkAreaLeft;
  Width := Screen.WorkAreaWidth;
  Height := Screen.WorkAreaHeight;
  StatusBar1.Panels[0].Width := StatusBar1.Width - 130;
  // Ajusta a barra de ferramentas na inicializacao
  SetaTBarReg('FFFF-FFFF');
  // Atualiza a barra de status
  AtualizaBarraStatus;
end;

procedure TfrmMain.Timer1Timer(Sender: TObject);
begin
  AtualizaBarraStatus;
end;

// Habilita / Desabilita os botoes da barra de ferramentos (ToolBar)
procedure TfrmMain.SetaTBarReg(PStatus: string);
var
  VInd: integer;
  VBool: boolean;
begin
  for VInd := 1 to 9 do begin
    if PStatus[VInd] = 'T' then VBool := true
    else VBool := false;
    TBarReg.Buttons[Vind-1].Enabled := VBool;
  end;
end;

procedure TfrmMain.AtualizaBarraStatus;
begin
  Statusbar1.Panels[1].Text := ' '+formatdatetime ('dd/mm/yyyy', now); // para data
  Statusbar1.Panels[2].Text := ' '+formatdatetime ('hh:mm', now); //para hora
end;

procedure TfrmMain.mnuPacienteClick(Sender: TObject);
begin
  if frmPaciente = nil then
    frmPaciente := TfrmPaciente.Create(frmMain);
  frmPaciente.Show;
  frmPaciente.WindowState := WsNormal;
end;

procedure TfrmMain.mnuMedicoClick(Sender: TObject);
begin
  if frmMedico = nil then
     frmMedico := TfrmMedico.Create(frmMain);
  frmMedico.Show;
  frmMedico.WindowState := WsNormal;
end;

procedure TfrmMain.tbtPrimeiroClick(Sender: TObject);
begin
  frmMain.ActiveMDIChild.Tag := 1;
  frmMain.ActiveMDIChild.CloseQuery;
end;

procedure TfrmMain.tbtAnteriorClick(Sender: TObject);
begin
  frmMain.ActiveMDIChild.Tag := 2;
  frmMain.ActiveMDIChild.CloseQuery;
end;

procedure TfrmMain.tbtProximoClick(Sender: TObject);
begin
  frmMain.ActiveMDIChild.Tag := 3;
  frmMain.ActiveMDIChild.CloseQuery;
end;

procedure TfrmMain.tbtUltimoClick(Sender: TObject);
begin
  frmMain.ActiveMDIChild.Tag := 4;
  frmMain.ActiveMDIChild.CloseQuery;
end;

procedure TfrmMain.tbtNovoClick(Sender: TObject);
begin
  frmMain.ActiveMDIChild.Tag := 5;
  frmMain.ActiveMDIChild.CloseQuery;
end;

procedure TfrmMain.tbtSalvarClick(Sender: TObject);
begin
  frmMain.ActiveMDIChild.Tag := 6;
  frmMain.ActiveMDIChild.CloseQuery;
end;

procedure TfrmMain.tbtExcluirClick(Sender: TObject);
begin
  frmMain.ActiveMDIChild.Tag := 7;
  frmMain.ActiveMDIChild.CloseQuery;
end;

procedure TfrmMain.tbtCancelarClick(Sender: TObject);
begin
  frmMain.ActiveMDIChild.Tag := 8;
  frmMain.ActiveMDIChild.CloseQuery;
end;

end.
